import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    homepageHTML: "",
    forceImport: false,
    XAccessToken: sessionStorage.getItem("XAccessToken"),
    SysAccessToken: sessionStorage.getItem("SysAccessToken"),
    articleHTML:sessionStorage.getItem("articleHTML")?sessionStorage.getItem("articleHTML"):false,
    articleChange:sessionStorage.getItem("articleChange")?sessionStorage.getItem("articleChange"):false,
  },
  mutations: {
    setHomepageHTML(state, html, key) {
      state.homepageHTML = html;
    },
    triggerForceImport(state) {
      state.forceImport = !state.forceImport;
    },
    setArticleHTML(state, html) {
      state.articleHTML = html;
      sessionStorage.setItem("articleHTML",html);
      sessionStorage.setItem("articleChange",true);
    }
  },
  getters: {
    getArticleHTML(state){
      sessionStorage.setItem("articleChange",false);
      return state.articleHTML;
    },
    getArticleChange(state) {
      return state.articleChange;
    }
  },
});
